package service

import (
	"context"

	"github.com/go-kratos/kratos/v2/log"

	pb "review-service/api/review"
	"review-service/internal/data"
	"review-service/internal/model/mysqlmodel"
)

type ReviewService struct {
	pb.UnimplementedReviewServer
	rep *data.ReviewRepo
	log *log.Helper
}

func NewReviewService(rep *data.ReviewRepo, logger log.Logger) *ReviewService {
	return &ReviewService{rep: rep, log: log.NewHelper(logger)}
}

func (s *ReviewService) CreateReview(ctx context.Context, req *pb.CreateReviewRequest) (*pb.CreateReviewReply, error) {
	reviewInfo := &mysqlmodel.ReviewInfo{
		UserID:         uint(req.UserId),
		Content:        req.Content,
		ShopID:         uint(req.ShopId),
		ShopScore:      uint8(req.ShopScore),
		LogisticsScore: uint8(req.LogisticsScore),
		HavePicture:    req.HavePicture,
		Status:         mysqlmodel.ReviewStatusPending, // 默认待审核
	}
	s.log.Infof("CreateReview req: %v", req)
	if err := s.rep.SaveReviewInfo(ctx, reviewInfo); err != nil {
		s.log.Errorf("CreateReview failed, err: %v", err)
		return nil, err
	}
	s.log.Infof("CreateReview success, reviewID: %d", reviewInfo.ID)
	// 如果有图片的话，更新 url
	return &pb.CreateReviewReply{}, nil
}
func (s *ReviewService) UploadImage(ctx context.Context, req *pb.UploadImageRequest) (*pb.UploadImageReply, error) {
	return &pb.UploadImageReply{}, nil
}
func (s *ReviewService) UpdateReview(ctx context.Context, req *pb.UpdateReviewRequest) (*pb.UpdateReviewReply, error) {
	return &pb.UpdateReviewReply{}, nil
}
func (s *ReviewService) DeleteReview(ctx context.Context, req *pb.DeleteReviewRequest) (*pb.DeleteReviewReply, error) {
	return &pb.DeleteReviewReply{}, nil
}
func (s *ReviewService) GetReview(ctx context.Context, req *pb.GetReviewRequest) (*pb.GetReviewReply, error) {
	return &pb.GetReviewReply{}, nil
}
func (s *ReviewService) ListReview(ctx context.Context, req *pb.ListReviewRequest) (*pb.ListReviewReply, error) {
	return &pb.ListReviewReply{}, nil
}
